package main

import (
	"fmt"
	"time"
)

/* func main() {
	fmt.Println(time.Now())//获取当前时间
	myTimer := time.NewTimer(time.Second * 2)//定时2秒
	time1 := <-myTimer.C//将系统写入channel C中的时间读出
	fmt.Println(time1)
} */

//3种定时方法
/* func main() {
	//1.sleep
	time.Sleep(time.Second)
	//2.Time.C
	fmt.Println(time.Now())                   //获取当前时间
	myTimer := time.NewTimer(time.Second * 2) //定时2秒
	time1 := <-myTimer.C                      //将系统写入channel C中的时间读出
	fmt.Println(time1)
	//3.Time.After
	time1 = <-time.After(time.Second * 3)
	fmt.Println(time1)
} */

//定时器的停止和重置

func main() {
	myTimer := time.NewTimer(time.Second * 3)
	myTimer.Reset(time.Second * 1) //定时器重置
	go func() {
		<-myTimer.C
		fmt.Println("子goroutine,定时完毕")
	}()
	//myTimer.Stop() //计时器停止

	for {
	}
}
